<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
</head>

<body>
    <header class="aui-bar aui-bar-nav">
        <a class="aui-pull-left" tapmode onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">购买记录</div>
    </header>
    <div class="aui-bar-nav-d"></div>


    <style>
        body {
            background: #fff;
        }
    </style>
    <div class="licai-buy-reocrd-t" id="renshu">
    </div>
    <div id="list"></div>
    <!-- <table class="licai-buy-reocrd-d" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td>购买用户</td>
        <td>购买金额</td>
        <td>购买时间</td>
    </tr>
    <tr>
        <td>**明</td>
        <td>20000元</td>
        <td>2018-05-23 16:28:31</td>
    </tr>
    <tr>
        <td>**明</td>
        <td>20000元</td>
        <td>2018-05-23 16:28:31</td>
    </tr>
    <tr>
        <td>**明</td>
        <td>20000元</td>
        <td>2018-05-23 16:28:31</td>
    </tr>
    <tr>
        <td>**明</td>
        <td>20000元</td>
        <td>2018-05-23 16:28:31</td>
    </tr>
    <tr>
        <td>**明</td>
        <td>20000元</td>
        <td>2018-05-23 16:28:31</td>
    </tr>
</table> -->

</body>

<script type="text/template" id="template">
    <table class="licai-buy-reocrd-d" cellpadding="0" cellspacing="0" border="0">
        <tr id="hid">
            <td>购买用户</td>
            <td>购买金额</td>
            <td>购买时间</td>
        </tr>
        {{~it:value:index}}
        <tr>
            <td>{{=value.user_name}}</td>
            <td>
                <p class="money">{{=value.money}}</p>元</td>
            <td class="time">{{=value.create_time}}</td>
        </tr>
        {{~}}
    </table>
</script>

<script type="text/javascript">
    var id = '';
    var load_count = '';

    apiready = function() {
        id = api.pageParam.id;
        load_count = api.pageParam.load_count;

        $("#renshu").text("已有" + load_count + "人购买");
        // alert(id);
        addObserver();
        load_list();
    }

    function closeWin() {
        api.closeWin({});
    }

    function addObserver() {
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0
            }
        }, function(ret, err) {

            load_list(true);
        });
    }

    // 加载列表
    function load_list(n) {

        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });

        if (n) {
            page += 1;
        } else {
            page = 1;
        }

        api.ajax({
            url: webAddress + '/index.php?ctl=app_deal&act=load_list&time_limit=' + id + '&page=' + page,
            method: 'get',
        }, function(ret, err) {

            if (ret) {

                if (ret.status == 0) {
                    alert(ret.info);
                } else {
                    // alert( JSON.stringify( ret ) );

                    for (var i = 0; i < ret.load_list.length; i++) {
                        ret.load_list[i].user_name = hidden_name(ret.load_list[i].user_name);
                        ret.load_list[i].money = outputmoney(ret.load_list[i].money);
                        ret.load_list[i].create_time = getDate(ret.load_list[i].create_time);

                    }
                    updateList(ret.load_list, page, ret.load_list.length);

                    api.hideProgress();
                }
            } else {
                alert(JSON.stringify(err));
                api.hideProgress();
            }
        });
    }

    // doT
    function updateList(data, page, num) {
        // alert($api.jsonToStr(data));
        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');



        if (page == 1) {
            $api.html(list, html);

        } else {
            if (data == '') {
                api.toast({
                    msg: '没有更多了',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            $api.append(list, html);
        }

        $('#hid').attr('id','hid'+page);
        if (page != 1) {
          $("#hid"+page).hide();
        }
        
        api.parseTapmode();
    }
</script>

</html>
